//
//  InquiryMain_HotGoodsList_Cell_WX.m
//  ZITHER
//
//  Created by weixin on 2019/3/14.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "InquiryMain_HotGoodsList_Cell_WX.h"

@implementation InquiryMain_HotGoodsList_Cell_WX

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.View setCornerRadiusWithRadius:10 isMasks:YES];
//    [self.View setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:0.5];
    self.title.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
}

-(void)setModel:(goodVOsModel *)model{
    
    _model = model;
    
    if (![model.traced isEqualToString:@"false"]) {
        /** 追踪列表 */
        self.subTitle.textColor = baseColorTheme;
    }else{
        self.subTitle.textColor = [UIColor blackColor];
    }

    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.goodInfo.imageDefault];
    NSLog(@"%@",str);
    
    NSString * strTitle = [NSString stringWithFormat:@"%@%@",model.goodInfo.seriesInfo.brand.brandNameNative,model.goodInfo.seriesInfo.seriesNameNative];
    
    if (strTitle==0) {
        self.title.hidden = YES;
    }else{
        self.title.hidden = NO;
        self.title.text = strTitle;
    }
    
    if (model.goodInfo.goodNameNative.length==0) {
        self.subTitle.hidden = YES;
    }else{
        self.subTitle.text =model.goodInfo.goodNameNative;
        self.subTitle.hidden = NO;
    }
    [self.img sd_setImageWithURL:[NSURL URLWithString:str]];

    
    if (self.State) {
        [self setSearchResult:model];
    }else{
        [self setHotGoodsList:model];
    }
    

}


-(void)setSearchResult:(goodVOsModel *)model{
    //_officialPrice
    //_secondHandPrice
    //_secondHandPriceMax

    
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    
    int priceInt = [model.goodInfo.secondHandPrice intValue];
    NSString *price1 = @"";
    NSString *price2 = @"";
    NSString *priceofficial = @"";

    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price1= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price1 = @"暂无";
    }
    priceInt = [model.goodInfo.secondHandPriceMax intValue];
    
    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price2= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price2 = @"暂无";
    }
    
    priceInt = [model.goodInfo.officialPrice intValue];
    
    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        priceofficial= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        priceofficial = @"暂无公价";
    }
    
    
    
    self.secondHandLab.text = [NSString stringWithFormat:@"二手价 ￥%@ - ￥%@",price1,price2]; //二手价
    
    int officialPriceeInt = [model.goodInfo.officialPrice intValue];
    
    if ([price2 isEqualToString:@"暂无"] && [price1 isEqualToString:@"暂无"]) {
        self.secondHandLab.textColor = HexColor(0x999999);
        self.secondHandLab.text = @"暂无二手价";
        self.secondHandLab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
        
    }else{
        if (officialPriceeInt<[model.goodInfo.secondHandPriceMax intValue]) {
            self.secondHandLab.textColor = HexColor(0xff6f6f);
        }else{
            self.secondHandLab.textColor = HexColor(0x333333);
        }
        self.secondHandLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
        
    }
    
    
    if (![priceofficial isEqualToString:@"暂无公价"]) {
        self.officialLab.text = [NSString stringWithFormat:@"¥ %@",priceofficial];
        self.officialLab.textColor = HexColor(0x333333);
    }else{
        self.officialLab.text = @"暂无公价";
        self.officialLab.textColor = HexColor(0x999999);
    }
    self.officialLab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:17];
    
}

-(void)setHotGoodsList:(goodVOsModel *)model{
  
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    
    int priceInt = [model.goodInfo.secondHandPrice intValue];
    NSString *price1 = @"";
    NSString *price2 = @"";
    
    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price1= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price1 = @"暂无";
    }
    priceInt = [model.goodInfo.secondHandPriceMax intValue];
    
    if (priceInt != 0) {
        moneyFormatter.positiveFormat = @"###,##0";
        price2= [moneyFormatter stringFromNumber:@(priceInt)];
    }else{
        price2 = @"暂无";
    }
    self.secondHandLab.text = [NSString stringWithFormat:@"二手价 ￥%@ - ￥%@",price1,price2]; //二手价
    
    int officialPriceeInt = [model.goodInfo.officialPrice intValue];
    
    if ([price2 isEqualToString:@"暂无"] && [price1 isEqualToString:@"暂无"]) {
        self.secondHandLab.textColor = HexColor(0x999999);
        self.secondHandLab.text = @"暂无参考价";
        self.secondHandLab.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
        
    }else{
        if (officialPriceeInt<[model.goodInfo.secondHandPriceMax intValue]) {
            self.secondHandLab.textColor = HexColor(0xff6f6f);
        }else{
            self.secondHandLab.textColor = HexColor(0x333333);
        }
        self.secondHandLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
        
    }
    
    if (![model.goodInfo.sourceCount isEqualToString:@"0"]) {

        self.officialLab.text = [NSString stringWithFormat:@"%@个货源",model.goodInfo.sourceCount];
        
        self.officialLab.textColor = HexColor(0x333333);
        
    }else{
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]) {
            self.officialLab.text = @"暂无相关货源";
        }else{
            self.officialLab.text = @"商家备货中";
        }
        self.officialLab.textColor = HexColor(0x999999);
    }
    
}

@end
